var all_img = document.querySelectorAll("img"),
	re_load = document.querySelector(".re_load");

function preloadimages(arr) {
	re_load = document.querySelector(".re_load");
	var newimages = [],
		loadedimages = 0,
		num = 25;
	var postaction = function() {} //此处增加了一个postaction函数
	var arr = (typeof arr != "object") ? [arr] : arr //这是判断是不是十足
	function imageloadpost() {
		var re_load = document.querySelector(".re_load");
		loadedimages++
		re_load.innerHTML = "<span>" + Math.floor((loadedimages / arr.length) * 100) + "%</span>"
//		console.log(arr.length);
		console.log(loadedimages);
		if(loadedimages == arr.length) {
			postaction(newimages) //此处增加了一个postaction函数
		}
	}
	for(var i = 0; i < arr.length; i++) {
		newimages[i] = new Image()
		newimages[i].src = arr[i]
		newimages[i].onload = function() {
			imageloadpost()
		}
		newimages[i].onerror = function() {
			imageloadpost()
		}
	}
	return { //此处返回一个空白对象的done方法
		done: function(f) {
			postaction = f || postaction
		}
	}
}
preloadimag = ['img/running/road.jpg', 'img/running/car.png', 'img/running/car2.png', 'img/run/bg_run.png', 'img/success/bg_suc.jpg','img/running/btn_switch.png']
for(var i = 0; i < all_img.length; i++) {
	preloadimag.push(all_img[i].src)
}	
preloadimages(preloadimag).done(function() {
	re_load.style.display = "none"
});
console.log(preloadimag);